home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig11_17.jar / Ch11 / Fig11_17 / Fig11_17.cpp
C/C++ Source or Header  |  1997-11-09  |  718b  |  32 lines

  1. // Fig. 11.17: fig11_17.cpp 
  2. // Controlling precision of floating-point values
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9.    double root2 = sqrt( 2.0 );
  10.    int places;
  11.  
  12.    cout << setiosflags( ios::fixed)
  13.         << "Square root of 2 with precisions 0-9.\n"
  14.         << "Precision set by the "
  15.         << "precision member function:" << endl;
  16.  
  17.    for ( places = 0; places <= 9; places++ ) {
  18.       cout.precision( places );
  19.       cout << root2 << '\n';
  20.    }
  21.  
  22.    cout << "\nPrecision set by the "
  23.         << "setprecision manipulator:\n";
  24.  
  25.    for ( places = 0; places <= 9; places++ )
  26.       cout << setprecision( places ) << root2 << '\n';
  27.  
  28.    return 0;
  29. }
  30.  
  31.  
  32.